<?php
namespace App\V3\V3_2_7\Models;

use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;


class CloudDevicePrinterModel extends Model
{
    protected $table        = 'cloud_device_printer'; //表名
    protected $primaryKey   = 'cdp_id'; //表主键
    protected $dateFormat   = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }


    /**
     * 检查打印机是否可用 有效
     * driver_type = 是否已适配
     * action_status = usb 是否插入
     */
    public function isValid()
    {
        if( $this->cdp_driver_type == 1 &&
            $this->cdp_action_status == 'bind' &&
            ($this->cdp_support_status == '' || $this->cdp_support_status == 0)){
            return true;
        }else{
            return false;
        }
    }


    /**
     * 计算当前打印花费多少钱
     * 费用：激光和喷墨为 0.03元/次，其它都为 0.01元/次
     */
    public function jobMoney()
    {
        if($this->cdp_printer_species == 4 || $this->cdp_printer_species == 5){
            return 0.03;
        }else{
            return 0.01;
        }
    }


}
